/*
 * dbgmsg.h
 *
 *  Created on: May 16, 2013
 *      Author: Lucifer
 */

#ifndef __DBGMSG_H__
#define __DBGMSG_H__

#ifdef  __cplusplus
extern "C" {
#endif

/* Level identifiers */
typedef enum
{
	DLI_INFO, DLI_TRACE, DLI_WARN, DLI_ERROR, DLI_ASSERT,

	DLI_LAST
} DBG_LEVEL_ID;

/**
 * The global debug trace level.
 */
extern unsigned int dbg_level;

/**
 * Print a debug trace message.
 * @param[in] level
 * @param[in] channel
 * @param[in] function
 * @param[in] file
 * @param[in] line
 * @param[in] format
 */
extern void dbg_printf(DBG_LEVEL_ID level, const char* channel, const char* function, const char* file, int line,
		const char* format, ...);

#ifdef __GNUC__
#define BFX_DBGPRINTF(level, channel)	\
{	\
	if (dbg_level & (1 << (level))) {	\
		DBG_LEVEL_ID __levid = level;	\
		const char*	__chname = channel;	\
		DBG_PRINTF2

#define DBG_PRINTF2(args...)	\
		dbg_printf(__levid, __chname, __FUNCTION__, __FILE__, __LINE__, args);	\
	}	\
}

#else	//	__GNUC__

#define BFX_DBGPRINTF(level, channel)	\
{	\
    if (dbg_level & (1 << (level))) {	\
        DBG_LEVEL_ID __levid = level;	\
		const char*	__chname = channel;	\
        DBG_PRINTF2

#define DBG_PRINTF2(...)	\
      dbg_printf(__levid, __chname, __FUNCTION__, __FILE__, __LINE__, __VA_ARGS__);	\
    }	\
}

#endif	//	!__GNUC__

#define	DEFDBGCHAN	"DEFAULT"

#define BFX_DBGINFO \
	BFX_DBGPRINTF(DLI_INFO, DEFDBGCHAN)
#define BFX_DBGINFO_(ch) \
	BFX_DBGPRINTF(DLI_INFO, ch)

#define BFX_DBGTRACE \
	BFX_DBGPRINTF(DLI_TRACE, DEFDBGCHAN)
#define BFX_DBGTRACE_(ch) \
	BFX_DBGPRINTF(DLI_TRACE, ch)

#define BFX_DBGWARN \
	BFX_DBGPRINTF(DLI_WARN, DEFDBGCHAN)
#define BFX_DBGWARN_(ch) \
	BFX_DBGPRINTF(DLI_WARN, ch)

#define BFX_DBGERROR \
	BFX_DBGPRINTF(DLI_ERROR, DEFDBGCHAN)
#define BFX_DBGERROR_(ch) \
	BFX_DBGPRINTF(DLI_ERROR, ch)

#ifdef  __cplusplus
}
#endif

#endif /* __DBGMSG_H__ */
